<template>
  <a-modal
    centered
    v-model="visible"
    @cancel="cancel"
    title="服务项登记"
    width="75%"
  >
    <template slot="footer">
      <a-button
        @click="cancel"
        style="background: #d7d7d7; color: #fff; border: none"
        >取消</a-button
      >
      <a-button :loading="loading" type="primary" @click="handleOk"
        >保存</a-button
      >
    </template>
    <!-- 表格 -->
    <h3>整柜服务</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="cabinetData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="10%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.serviceName }}
          </template>
        </a-table-column>
        <!-- 数量单位 -->
        <a-table-column
          key="quantity"
          data-index="quantity"
          align="center"
          width="8%"
        >
          <span slot="title">数量</span>
          <template slot-scope="text, record">
            <a-input-number
              style="width: 100%"
              :min="0"
              @change="changeQuantity(record)"
              :disabled="
                record.ruleId == null ||
                record.ruleId == undefined ||
                record.ruleId == ''
              "
              placeholder="数量"
              v-model="record.quantity"
            />
          </template>
        </a-table-column>
        <!-- 服务选择 -->
        <a-table-column
          key="ruleId"
          data-index="ruleId"
          align="center"
          width="14%"
        >
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <a-select
              show-search
              style="width: 100%"
              option-filter-prop="children"
              v-model="record.ruleId"
              @change="(e, option) => changecaBine(e, option, record)"
              placeholder="服务选择"
            >
              <a-select-option
                :value="val.ruleId"
                :val="val"
                v-for="val in record.serviceSelect"
                :key="val.ruleId"
              >
                {{ val.ruleName }}
              </a-select-option>
            </a-select>
          </template>
        </a-table-column>
        <!-- 额外规则 -->
        <a-table-column
          key="ewaiguize"
          data-index="ewaiguize"
          align="center"
          width="50%"
        >
          <span slot="title">额外规则</span>
          <template slot-scope="text, record">
            <div v-for="(item, index) in record.extraList" :key="index">
              <div class="service-total">
                <a-checkbox
                  @change="(e) => onChangeexceedWeight(e, item)"
                  :checked="item.isOverweight == '0'"
                >
                  是否超重
                </a-checkbox>
                <a-input-number
                  style="width: 12%; margin-right: 15px"
                  :min="0"
                  @change="changeQuantityWeight(item)"
                  :disabled="item.isOverweight == '1'"
                  placeholder="数量"
                  v-model="item.overweightTotal"
                />
                <a-select
                  style="width: 32%; margin-right: 20px"
                  show-search
                  option-filter-prop="children"
                  v-model="item.extraTitle"
                  @change="(e, option) => changeExtraIndex(e, option, item)"
                  placeholder="范围"
                >
                  <a-select-option
                    :value="val.value"
                    v-for="val in item.weightUnits"
                    :key="val.key"
                  >
                    {{ val.value }}
                  </a-select-option>
                </a-select>
                <a-checkbox
                  @change="(e) => onChangeexceedBox(e, item)"
                  :checked="item.isExceedBox == '0'"
                >
                  是否超箱
                </a-checkbox>
                <a-input-number
                  :min="0"
                  style="width: 12%; margin-right: 15px"
                  placeholder="数量"
                  @change="changeQuantityBox(item)"
                  :disabled="item.isExceedBox == '1'"
                  v-model="item.exceedBoxTotal"
                />
                <div class="icon-list">
                  <a-icon
                    style="color: #3eae7c"
                    type="plus-circle"
                    theme="filled"
                    @click="addOtherRule(record)"
                    v-if="
                      record.extraList.length === 1 ||
                      record.extraList.length - 1 === index
                    "
                  />
                  <a-icon
                    type="minus-circle"
                    style="color: #b4b4b4"
                    theme="filled"
                    @click="delOtherRule(record, item)"
                  />
                </div>
              </div>
            </div>
          </template>
        </a-table-column>
        <!-- 操作 -->
        <a-table-column align="center">
          <span slot="title">操作</span>
          <template slot-scope="text, record">
            <a
              @click="() => addSerRule(record)"
              href="javascript:;"
              style="color: #2929e0; border-bottom: 1px solid #2929e0"
              >新增</a
            >
            <a-divider type="vertical" />
            <a
              @click="() => delSerRule(record)"
              href="javascript:;"
              style="color: #f00; border-bottom: 1px solid #f00"
              >移除</a
            >
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
    <h3>其他服务</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="serviceData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <!-- 服务名称 -->
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="12%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.serviceName }}
          </template>
        </a-table-column>
        <!-- 数量单位 -->
        <a-table-column
          key="quantity"
          data-index="quantity"
          align="center"
          width="8%"
        >
          <span slot="title">数量</span>
          <template slot-scope="text, record">
            <a-input-number
              style="width: 100%"
              :min="0"
              @change="changeQuantity(record)"
              :disabled="
                record.ruleId == null ||
                record.ruleId == undefined ||
                record.ruleId == ''
              "
              placeholder="数量"
              v-model="record.quantity"
            />
          </template>
        </a-table-column>
        <!-- 服务选择 -->
        <a-table-column
          key="ruleId"
          data-index="ruleId"
          align="center"
          width="50%"
        >
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <a-select
              show-search
              style="width: 100%"
              option-filter-prop="children"
              v-model="record.ruleId"
              @change="(e, option) => changeSerChoose(e, option, record)"
              placeholder="服务选择"
            >
              <a-select-option
                :value="val.ruleId"
                :name="val.ruleName"
                :val="val"
                v-for="val in record.serviceSelect"
                :key="val.key"
                :ruleType="val.ruleType"
              >
                {{ val.ruleName }}
              </a-select-option>
            </a-select>
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
    <h3>换标/贴标</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="bidData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="12%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.serviceName }}
          </template>
        </a-table-column>
        <!-- 数量单位 -->
        <a-table-column
          key="quantity"
          data-index="quantity"
          align="center"
          width="8%"
        >
          <span slot="title">数量</span>
          <template slot-scope="text, record">
            <a-input-number
              style="width: 100%"
              :min="0"
              @change="changeQuantity(record)"
              :disabled="
                record.ruleId == null ||
                record.ruleId == undefined ||
                record.ruleId == ''
              "
              placeholder="数量"
              v-model="record.quantity"
            />
          </template>
        </a-table-column>
        <!-- 服务选择 -->
        <a-table-column
          key="ruleId"
          data-index="ruleId"
          align="center"
          width="12%"
        >
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <a-select
              show-search
              style="width: 100%"
              option-filter-prop="children"
              v-model="record.ruleId"
              @change="(e, option) => changeSerChoose(e, option, record)"
              placeholder="服务选择"
            >
              <a-select-option
                :value="val.ruleId"
                v-for="val in record.serviceSelect"
                :key="val.key"
                :val="val"
                :name="val.ruleName"
                :ruleType="val.ruleType"
              >
                {{ val.ruleName }}
              </a-select-option>
            </a-select>
          </template>
        </a-table-column>
        <!-- 额外规则 -->
        <a-table-column
          key="ewaiguize"
          data-index="ewaiguize"
          align="center"
          width="50%"
        >
          <span slot="title">额外规则</span>
          <template slot-scope="text, record">
            <div v-for="(item, index) in record.extraList" :key="index">
              <a-checkbox
                @change="(e) => onChangeexceedWeight(e, item)"
                :checked="item.isOverweight == '0'"
              >
                是否超重
              </a-checkbox>
              <a-input-number
                style="width: 15%; margin-right: 15px"
                :min="0"
                @change="changeQuantityWeight(item)"
                :disabled="item.isOverweight == '1'"
                placeholder="数量"
                v-model="item.overweightTotal"
              />
              <a-checkbox
                @change="(e) => onChanCeedLength(e, item)"
                :checked="item.isOverlength == '0'"
              >
                是否超长
              </a-checkbox>
              <a-input-number
                :min="0"
                style="width: 15%; margin-right: 25px"
                placeholder="数量"
                @change="changeQuantityLength(item)"
                :disabled="item.isOverlength == '1'"
                v-model="item.overlengthTotal"
              />
            </div>
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
    <h3>入库</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="WarehousingData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <!-- 服务名称 -->
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="12%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.serviceName }}
          </template>
        </a-table-column>
        <!-- 数量单位 -->
        <a-table-column
          key="total1"
          data-index="total1"
          align="center"
          width="8%"
        >
          <span slot="title">数量</span>
          <template slot-scope="text, record">
            <a-input-number
              style="width: 100%"
              :min="0"
              @change="changeQuantity(record)"
              :disabled="
                record.ruleId == null ||
                record.ruleId == undefined ||
                record.ruleId == ''
              "
              placeholder="数量"
              v-model="record.quantity"
            />
          </template>
        </a-table-column>
        <!-- 服务选择 -->
        <a-table-column
          key="ruleId"
          data-index="ruleId"
          align="center"
          width="12%"
        >
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <a-select
              show-search
              style="width: 100%"
              option-filter-prop="children"
              v-model="record.ruleId"
              @change="(e, option) => changecaBine(e, option, record)"
              placeholder="服务选择"
            >
              <a-select-option
                :value="val.ruleId"
                v-for="val in record.serviceSelect"
                :key="val.key"
                :val="val"
                :ruleType="val.ruleType"
              >
                {{ val.ruleName }}
              </a-select-option>
            </a-select>
          </template>
        </a-table-column>
        <!-- 额外规则 -->
        <a-table-column
          key="ewaiguize"
          data-index="ewaiguize"
          align="center"
          width="50%"
        >
          <span slot="title">额外规则</span>
          <template slot-scope="text, record">
            <div v-for="(item, index) in record.extraList" :key="index">
              <div class="service-total">
                <a-checkbox
                  @change="(e) => onChangeexceedWeight(e, item)"
                  :checked="item.isOverweight == '0'"
                >
                  是否超重
                </a-checkbox>
                <a-input-number
                  style="width: 12%; margin-right: 15px"
                  :min="0"
                  @change="changeQuantityWeight(item)"
                  :disabled="item.isOverweight == '1'"
                  placeholder="数量"
                  v-model="item.overweightTotal"
                />
                <a-select
                  style="width: 32%; margin-right: 20px"
                  show-search
                  option-filter-prop="children"
                  v-model="item.extraTitle"
                  @change="(e, option) => changeExtraIndex(e, option, item)"
                  placeholder="范围"
                >
                  <a-select-option
                    :value="val.value"
                    v-for="val in item.weightUnits"
                    :key="val.key"
                  >
                    {{ val.value }}
                  </a-select-option>
                </a-select>
                <a-checkbox
                  @change="(e) => onChangeexceedBox(e, item)"
                  :checked="item.isExceedBox == '0'"
                >
                  是否超箱
                </a-checkbox>
                <a-input-number
                  :min="0"
                  style="width: 12%; margin-right: 15px"
                  placeholder="数量"
                  @change="changeQuantityBox(item)"
                  :disabled="item.isExceedBox == '1'"
                  v-model="item.exceedBoxTotal"
                />
                <div class="icon-list">
                  <a-icon
                    style="color: #3eae7c"
                    type="plus-circle"
                    theme="filled"
                    @click="addOtherRule(record)"
                    v-if="
                      record.extraList.length === 1 ||
                      record.extraList.length - 1 === index
                    "
                  />
                  <a-icon
                    type="minus-circle"
                    style="color: #b4b4b4"
                    theme="filled"
                    @click="delOtherRule(record, item)"
                  />
                </div>
              </div>
            </div>
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
    <h3>出库</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="mentionData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <!-- 服务名称 -->
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="12%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.serviceName }}
          </template>
        </a-table-column>
        <!-- 数量单位 -->
        <a-table-column
          key="total1"
          data-index="total1"
          align="center"
          width="8%"
        >
          <span slot="title">数量</span>
          <template slot-scope="text, record">
            <a-input-number
              style="width: 100%"
              :min="0"
              @change="changeQuantity(record)"
              :disabled="
                record.ruleId == null ||
                record.ruleId == undefined ||
                record.ruleId == ''
              "
              placeholder="数量"
              v-model="record.quantity"
            />
          </template>
        </a-table-column>
        <!-- 服务选择 -->
        <a-table-column
          key="ruleId"
          data-index="ruleId"
          align="center"
          width="12%"
        >
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <a-select
              show-search
              @change="(e, option) => changeSerChoose(e, option, record)"
              style="width: 100%"
              option-filter-prop="children"
              v-model="record.ruleId"
              placeholder="服务选择"
            >
              <a-select-option
                :value="val.ruleId"
                :val="val"
                :name="val.ruleName"
                v-for="val in record.serviceSelect"
                :key="val.key"
                :ruleType="val.ruleType"
              >
                {{ val.ruleName }}
              </a-select-option>
            </a-select>
          </template>
        </a-table-column>
        <!-- 额外规则 -->
        <a-table-column
          key="ewaiguize"
          data-index="ewaiguize"
          align="center"
          width="50%"
        >
          <span slot="title">额外规则</span>
          <template slot-scope="text, record">
            <div v-for="(item, index) in record.extraList" :key="index">
              <a-checkbox
                @change="(e) => onChangeRetention(e, item)"
                :checked="item.isRetention == '0'"
              >
                是否滞仓
              </a-checkbox>
              <a-input-number
                style="width: 15%; margin-right: 15px"
                :min="0"
                @change="changeQuantityRetention(item)"
                :disabled="item.isRetention == '1'"
                placeholder="天数"
                v-model="item.retention"
              />
            </div>
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
    <h3>清关服务</h3>
    <a-spin tip="Loading..." :spinning="spinning">
      <a-table
        size="small"
        bordered
        :data-source="clearanceData"
        :pagination="false"
        :scroll="{ x: 1200, y: 300 }"
      >
        <!-- 服务名称 -->
        <a-table-column
          key="serviceName"
          data-index="serviceName"
          align="center"
          width="15%"
        >
          <span slot="title">服务名称</span>
          <template slot-scope="text, record">
            {{ record.ruleName }}
          </template>
        </a-table-column>
        <!-- 额外规则 -->
        <a-table-column key="ewaiguize" data-index="ewaiguize" align="center">
          <span slot="title">服务选择</span>
          <template slot-scope="text, record">
            <div class="service-total2">
              <span>
                <a-checkbox
                  style="width: 20%"
                  @change="(e) => onchangeClean(e, record)"
                  :checked="record.isTrue == true"
                >
                  {{ record.ruleName }}
                </a-checkbox>
                <a-input-number
                  :disabled="record.ruleId == 13 && record.isTrue == false"
                  style="width: 25%"
                  :min="0"
                  v-if="record.ruleId == 13"
                  placeholder="HS Code超出数量"
                  v-model="record.quantity"
                />
                <a-input-number
                  :disabled="record.ruleId == 0 && record.isTrue == false"
                  style="width: 25%"
                  :min="0"
                  v-if="record.ruleId == 0"
                  placeholder="垫付费用"
                  :precision="6"
                  v-model="record.quantity"
                />
              </span>
            </div>
          </template>
        </a-table-column>
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
import {
  ser_service,
  ser_saveList,
} from "@/apis/clientSide/OrderManage/TransferIn";
export default {
  props: ["searchOne"],
  data() {
    return {
      tenantId: "",
      applyId: "",
      visible: false,
      loading: false,
      sysStoreHouseId: null,
      spinning: false,
      csdTeamId: null,
      schemeIdEndTime: null,
      schemeIdStartTime: null,
      tenantSchemeId: null,
      //入库
      WarehousingData: [
        {
          serviceType: 3,
          businessType: 0,
          quantity: null,
          serviceSelect: [],
          serviceName: "快递(普通箱子)",
          extraList: [
            {
              isExceedBox: 1,
              isOverweight: 1,
              weightUnits: [],
              exceedBoxTotal: null,
              overweightTotal: null,
              extraTitle: undefined,
              extraIndex: 1,
              key: 1,
            },
          ],
        },
        {
          serviceType: 4,
          businessType: 0,
          quantity: null,
          serviceSelect: [],
          serviceName: "散货(托盘入库)",
          extraList: [
            {
              isExceedBox: 1,
              isOverweight: 1,
              weightUnits: [],
              exceedBoxTotal: null,
              overweightTotal: null,
              extraTitle: undefined,
              extraIndex: 1,
              key: 1,
            },
          ],
        },
      ],
      //整柜服务
      cabinetData: [
        {
          serviceType: 0,
          businessType: 0,
          serviceName: "整柜服务",
          quantity: null,
          ruleId: null,
          serviceSelect: [],
          ruleType: null,
          ruleName: undefined,
          extraList: [
            {
              isExceedBox: 1,
              isOverweight: 1,
              weightUnits: [],
              exceedBoxTotal: null,
              overweightTotal: null,
              extraTitle: undefined,
              extraIndex: 1,
              key: 1,
            },
          ],
          key: 1,
        },
      ],
      //换标贴标
      bidData: [
        {
          serviceType: 7,
          businessType: 0,
          serviceName: "换标/贴标",
          ruleId: undefined,
          ruleType: null,
          serviceSelect: [],
          quantity: null,
          extraList: [
            {
              isOverweight: 1,
              isOverlength: 1,
              overweightTotal: null,
              overlengthTotal: null,
            },
          ],
          exceedBoxTotal: 0,
        },
      ],
      //到仓自提
      mentionData: [
        {
          serviceType: 8,
          businessType: 0,
          serviceName: "到仓自提（箱）",
          quantity: null,
          serviceSelect: [],
          extraList: [
            {
              isRetention: 1,
              retention: null,
            },
          ],
        },
        {
          serviceType: 9,
          businessType: 0,
          serviceName: "到仓自提（拖）",
          quantity: null,
          serviceSelect: [],
          extraList: [
            {
              isRetention: 1,
              retention: null,
            },
          ],
        },
      ],
      //清关规则
      clearanceData: [],
      //服务项数据
      serviceData: [
        {
          serviceType: 1,
          businessType: 0,
          quantity: null,
          serviceSelect: [],
          serviceName: "拣货处理费",
        },
        {
          serviceType: 2,
          businessType: 0,
          quantity: null,
          serviceSelect: [],
          serviceName: "打托和缠绕膜",
        },

        {
          serviceType: 5,
          businessType: 0,
          quantity: null,
          serviceSelect: [],
          serviceName: "拍照",
        },

        {
          serviceType: 6,
          businessType: 0,
          serviceName: "检查服务",
          quantity: null,
          serviceSelect: [],
        },
      ],
      schemeId: null,
    };
  },
  mounted() {
    this.$bus.$off("serviceRegistration");
    this.$bus.$on("serviceRegistration", (flag, row) => {
      this.tenantId = row.tenantId;
      this.csdTeamId = row.csdTeamId;
      this.applyId = row.transferWarehousingApplyId;
      this.getServiceList();
      this.visible = flag;
    });
  },
  methods: {
    //改变是否超重的数字
    changeQuantityWeight(item) {
      if (item.overweightTotal == null || item.overweightTotal == "") {
        item.overweightTotal = 0;
      }
    },
    //改变是否超箱的数字
    changeQuantityBox(item) {
      if (item.exceedBoxTotal == null || item.exceedBoxTotal == "") {
        item.exceedBoxTotal = 0;
      }
    },
    //改变是否超长的数字
    changeQuantityLength(item) {
      if (item.overlengthTotal == null || item.overlengthTotal == "") {
        item.overlengthTotal = 0;
      }
    },
    //改变是否滞仓的数字
    changeQuantityRetention(item) {
      if (item.retention == null || item.retention == "") {
        item.retention = 0;
      }
    },
    //改变数字
    changeQuantity(record) {
      if (record.quantity == null) {
        record.quantity = 0;
      }
    },
    //改变其他服务的服务选择
    changeSerChoose(e, option, record) {
      if (option) {
        record.ruleId = e;
        record.ruleType = option.data.attrs.ruleType;
        record.ruleName = option.data.attrs.name;
        record.discount = option.data.attrs.val.discount;
        record.discountFormer = option.data.attrs.val.discountFormer;
        record.discountType = option.data.attrs.val.discountType;
        record.quantity = 0;
      } else {
        record.ruleId = undefined;

        record.ruleType = null;
        record.ruleName = null;
        record.quantity = null;
      }
    },
    //改变整柜服务项选项
    changecaBine(e, option, record) {
      record.ruleId = option.data.attrs.val.ruleId;
      record.ruleType = option.data.attrs.val.ruleType;
      record.ruleName = option.data.attrs.val.ruleName;
      record.discount = option.data.attrs.val.discount;
      record.discountFormer = option.data.attrs.val.discountFormer;
      record.discountType = option.data.attrs.val.discountType;
      record.quantity = 0;
      record.extraList.forEach((item) => {
        item.weightUnits = [];
        item.extraTitle = undefined;
        item.extraIndex = null;
      });
      let arr = [
        {
          key: 1,
          value:
            option.data.attrs.val.extraRuleOneLeft +
            "~" +
            option.data.attrs.val.extraRuleOneRight,
          extraRuleOneLeft: option.data.attrs.val.extraRuleOneLeft,
          extraRuleOnePrice: option.data.attrs.val.extraRuleOnePrice,
          extraRuleOneRight: option.data.attrs.val.extraRuleOneRight,
          extraRuleOneUnit: option.data.attrs.val.extraRuleOneUnit,
        },
        {
          key: 2,
          value:
            option.data.attrs.val.extraRuleTowLeft +
            "~" +
            (option.data.attrs.val.extraRuleTowRight != null
              ? option.data.attrs.val.extraRuleTowRight
              : "不限"),
          extraRuleTowLeft: option.data.attrs.val.extraRuleTowLeft,
          extraRuleTowPrice: option.data.attrs.val.extraRuleTowPrice,
          extraRuleTowRight: option.data.attrs.val.extraRuleTowRight,
          extraRuleTowUnit: option.data.attrs.val.extraRuleTowUnit,
        },
      ];
      record.extraList.forEach((item) => {
        item.weightUnits = arr;
      });
    },
    //获取服务项数据
    async getServiceList() {
      this.spinning = true;
      let res = await ser_service(0, this.tenantId, this.applyId);
      if (res.code == "200") {
        this.sysStoreHouseId = res.responseBody.warehouseId;
        this.schemeId = res.responseBody.schemeId;
        this.schemeIdEndTime = res.responseBody.schemeIdEndTime;
        this.schemeIdStartTime = res.responseBody.schemeIdStartTime;
        this.tenantSchemeId = res.responseBody.tenantSchemeId;
        this.clearanceData = res.responseBody["1-0-2"];
        this.clearanceData.forEach((item) => {
          item.serviceType = 10;
          item.businessType = 0;
          this.$set(item, "isTrue", false);
          item.serviceName = "清关规则";
          if (item.ruleId == 13) {
            this.$set(item, "quantity", null);
          }
        });
        this.cabinetData[0].serviceSelect = res.responseBody["2-17"];
        this.serviceData[0].serviceSelect = res.responseBody["7-3"];
        this.serviceData[1].serviceSelect = res.responseBody["7-4"];
        this.WarehousingData[0].serviceSelect = res.responseBody["2-3"];
        this.WarehousingData[1].serviceSelect = res.responseBody["2-4"];
        this.serviceData[2].serviceSelect = res.responseBody["7-7"];
        this.serviceData[3].serviceSelect = res.responseBody["4-19"];
        this.bidData[0].serviceSelect = res.responseBody["7-1"];
        this.mentionData[0].serviceSelect = res.responseBody["7-3"];
        this.mentionData[1].serviceSelect = res.responseBody["7-4"];
        this.spinning = false;
      }
    },
    //关闭模态框
    cancel() {
      this.visible = false;
      setTimeout(() => {
        //入库
        this.WarehousingData = [
          {
            serviceType: 3,
            businessType: 0,
            quantity: null,
            serviceSelect: [],
            serviceName: "快递(普通箱子)",
            extraList: [
              {
                isExceedBox: 1,
                isOverweight: 1,
                weightUnits: [],
                exceedBoxTotal: null,
                overweightTotal: null,
                extraTitle: undefined,
                extraIndex: 1,
                key: 1,
              },
            ],
          },
          {
            serviceType: 4,
            businessType: 0,
            quantity: null,
            serviceSelect: [],
            serviceName: "散货(托盘入库)",
            extraList: [
              {
                isExceedBox: 1,
                isOverweight: 1,
                weightUnits: [],
                exceedBoxTotal: null,
                overweightTotal: null,
                extraTitle: undefined,
                extraIndex: 1,
                key: 1,
              },
            ],
          },
        ];
        //整柜服务
        this.cabinetData = [
          {
            serviceType: 0,
            businessType: 0,
            serviceName: "整柜服务",
            quantity: null,
            ruleId: null,
            serviceSelect: [],
            ruleType: null,
            ruleName: undefined,
            extraList: [
              {
                isExceedBox: 1,
                isOverweight: 1,
                weightUnits: [],
                exceedBoxTotal: null,
                overweightTotal: null,
                extraTitle: undefined,
                extraIndex: 1,
                key: 1,
              },
            ],
            key: 1,
          },
        ];
        //换标贴标
        this.bidData = [
          {
            serviceType: 7,
            businessType: 0,
            serviceName: "换标/贴标",
            ruleId: undefined,
            ruleType: null,
            serviceSelect: [],
            quantity: null,
            extraList: [
              {
                isOverweight: 1,
                isOverlength: 1,
                overweightTotal: null,
                overlengthTotal: null,
              },
            ],
            exceedBoxTotal: 0,
          },
        ];
        //到仓自提
        this.mentionData = [
          {
            serviceType: 8,
            businessType: 0,
            serviceName: "到仓自提（箱）",
            quantity: null,
            serviceSelect: [],
            extraList: [
              {
                isRetention: 1,
                retention: null,
              },
            ],
          },
          {
            serviceType: 9,
            businessType: 0,
            serviceName: "到仓自提（拖）",
            quantity: null,
            serviceSelect: [],
            extraList: [
              {
                isRetention: 1,
                retention: null,
              },
            ],
          },
        ];
        //清关规则
        this.clearanceData = [];
        //服务项数据
        this.serviceData = [
          {
            serviceType: 1,
            businessType: 0,
            quantity: null,
            serviceSelect: [],
            serviceName: "拣货处理费",
          },
          {
            serviceType: 2,
            businessType: 0,
            quantity: null,
            serviceSelect: [],
            serviceName: "打托和缠绕膜",
          },

          {
            serviceType: 5,
            businessType: 0,
            quantity: null,
            serviceSelect: [],
            serviceName: "拍照",
          },

          {
            serviceType: 6,
            businessType: 0,
            serviceName: "检查服务",
            quantity: null,
            serviceSelect: [],
          },
        ];
      }, 50);
    },
    //新增额外规则
    addOtherRule(record) {
      let obj = {
        isExceedBox: 1,
        isOverweight: 1,
        exceedBoxTotal: null,
        overweightTotal: null,
        extraTitle: undefined,
        extraIndex: record.extraList.length + 1,
        weightUnits: record.extraList[0].weightUnits,
        key: Math.random(),
      };
      record.extraList.push(obj);
    },
    //减额外规则
    delOtherRule(record, row) {
      if (record.extraList.length == 1) {
        this.$message.error("至少要有一条数量单位！");
        return false;
      }
      if (row.key) {
        record.extraList.forEach(async (item, index) => {
          if (item.key == row.key) {
            await record.extraList.splice(index, 1);
          }
        });
      }
    },
    //新增整柜服务
    addSerRule(record) {
      let obj = {
        serviceType: 0,
        businessType: 0,
        serviceName: "整柜服务",
        quantity: null,
        ruleId: null,
        serviceSelect: this.cabinetData[0].serviceSelect,
        ruleType: null,
        extraList: [
          {
            isExceedBox: 1,
            isOverweight: 1,
            weightUnits: [],
            exceedBoxTotal: null,
            overweightTotal: null,
            extraTitle: undefined,
            extraIndex: record.extraList.length + 1,
            key: Math.random(),
          },
        ],
        key: Math.random(),
      };
      this.cabinetData.push(obj);
    },
    //减整规服务
    delSerRule(record) {
      if (this.cabinetData.length == 1) {
        this.$message.error("至少要有一条整柜服务数据！");
        return false;
      }
      this.cabinetData.forEach((item, index) => {
        if (item.key == record.key) {
          this.cabinetData.splice(index, 1);
        }
      });
    },
    //是否超重
    onChangeexceedWeight(e, item) {
      if (e.target.checked) {
        item.isOverweight = 0;
        item.overweightTotal = 0;
      } else {
        item.isOverweight = 1;
        item.overweightTotal = null;
      }
    },
    //选择超重范围
    changeExtraIndex(e, option, item) {
      if (option) {
        item.extraIndex = option.data.key;
      }
    },
    //是否超箱
    onChangeexceedBox(e, item) {
      if (e.target.checked) {
        item.isExceedBox = 0;
        item.exceedBoxTotal = 0;
      } else {
        item.isExceedBox = 1;
        item.exceedBoxTotal = null;
      }
    },
    //是否超长
    onChanCeedLength(e, item) {
      if (e.target.checked) {
        item.isOverlength = 0;
        item.overlengthTotal = 0;
      } else {
        item.isOverlength = 1;
        item.overlengthTotal = null;
      }
    },
    //是否滞仓
    onChangeRetention(e, item) {
      if (e.target.checked) {
        item.isRetention = 0;
        item.retention = 0;
      } else {
        item.isRetention = 1;
        item.retention = null;
      }
    },
    async handleOk() {
      this.loading = true;
      let subFlag = false;
      //取清关服务被勾选的数据
      let clenaArr = this.clearanceData.filter((item) => {
        return item.isTrue == true;
      });
      //合并数组提交
      let submitArr = this.cabinetData
        .concat(this.bidData)
        .concat(this.mentionData)
        .concat(this.serviceData)
        .concat(clenaArr)
        .concat(this.WarehousingData);

      submitArr.forEach((item) => {
        if (item.ruleId) {
          subFlag = true;
        }
        if (item.extraList != undefined) {
          item.extraList.forEach((val) => {
            val.tenantId = this.tenantId;
            val.weightUnits = JSON.stringify(val.weightUnits);
          });
        }
        item.sysStoreHouseId = this.sysStoreHouseId;
        item.sysChargingSchemeId = this.schemeId;
        item.csdTeamId = this.csdTeamId;
        item.tenantId = this.tenantId;
        item.businessName = "转运入库";
        item.sysChargingTenantSchemeIdEndTime = this.schemeIdEndTime;
        item.sysChargingTenantSchemeIdStartTime = this.schemeIdStartTime;
        item.sysChargingTenantSchemeId = this.tenantSchemeId;
      });
      if (subFlag) {
        let res = await ser_saveList(this.applyId, submitArr);
        if (res.code == "10000") {
          this.loading = false;
          this.cancel();
          this.searchOne(this.applyId);
        }
      } else {
        this.loading = false;
        this.$message.error("请选择服务项或点击取消关闭！");
        return false;
      }
    },
    //改变复选框
    onchangeClean(e, record) {
      if (e.target.checked) {
        record.isTrue = true;
      } else {
        record.isTrue = false;
      }
    },
    // 下拉框过滤
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
  },
};
</script>

<style lang="less" scoped>
/deep/.service-total {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  .icon-list {
    width: 60px;
    display: flex;
    align-items: center;
    i {
      font-size: 24px;
    }
    i:first-child {
      margin-right: 8px;
    }
  }
}
.service-total2 {
  display: flex;
  span {
    width: 100%;
    text-align: left;
  }
}
</style>
